{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python_defaultSpec_1600852445665",
   "display_name": "Python 3.7.7 64-bit ('d2l': conda)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[tensor([[0, 1, 2, 3],\n         [4, 5, 6, 7]]),\n tensor([[ 8,  9, 10, 11],\n         [12, 13, 14, 15]]),\n tensor([[16, 17, 18, 19],\n         [20, 21, 22, 23]])]"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "import torch\n",
    "X = []\n",
    "X.append(torch.arange(8).reshape(2,4))\n",
    "X.append(torch.arange(8,16).reshape(2,4))\n",
    "X.append(torch.arange(16,24).reshape(2,4))\n",
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "tensor([[ 0,  1,  2,  3],\n        [ 4,  5,  6,  7],\n        [ 8,  9, 10, 11],\n        [12, 13, 14, 15],\n        [16, 17, 18, 19],\n        [20, 21, 22, 23]])"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "Y = torch.cat(X, dim=0)\n",
    "Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "torch.Size([6, 4])"
     },
     "metadata": {},
     "execution_count": 6
    }
   ],
   "source": [
    "Y.shape # 6 = 2 * 3    2是单个tensor高，3是X的长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "tensor([[[ 0,  1,  2,  3],\n         [ 4,  5,  6,  7]],\n\n        [[ 8,  9, 10, 11],\n         [12, 13, 14, 15]],\n\n        [[16, 17, 18, 19],\n         [20, 21, 22, 23]]])"
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "source": [
    "# X是个list，长度是时间步数，X每项是(批量大小, 词典大小)\n",
    "# 时间步数3  批量大小2   词典大小4\n",
    "Y2 = torch.stack(X)\n",
    "Y2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "torch.Size([3, 2, 4])"
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "source": [
    "Y2.shape # 形状为(时间步数, 批量大小, 输入个数:词典大小)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}